<div class="card mb-4">
  <div class="card-header d-flex align-items-center justify-content-between">
    <h5 class="card-title"><%= Spree.t(:inventory) %></h5>

    <% if can?(:manage, Spree::StockLocation) %>
      <%= link_to_with_icon 'adjustments', Spree.t(:manage_stock_locations), spree.admin_stock_locations_path, class: 'btn btn-sm btn-light' %>
    <% end %>
  </div>
  <div class="card-body">
    <div class="custom-control custom-checkbox mb-4">
      <%= f.check_box :track_inventory,
            class: 'custom-control-input',
            data: {
              product_form_target: 'trackInventoryCheckbox',
              action: 'product-form#toggleQuantityTracked'
            }
          %>
      <%= f.label :track_inventory, Spree.t(:track_quantity), class: 'custom-control-label' %>
    </div>
    <div
      class="master-variant-quantity-form <%= @product.has_variants? || !@product.track_inventory ? 'd-none' : '' %>"
      data-product-form-target="<%= @product.has_variants? ? '' : 'quantityForm' %>"
    >
      <h6 class="font-weight-bold"><%= Spree.t(:quantity) %></h6>
      <hr class="mt-0">
      <div class="mb-4">
        <%= f.fields_for :master, @product.master do |vf| %>
          <%= vf.fields_for :stock_items do |sif| %>
            <%= sif.hidden_field :stock_location_id %>
            <div class="row mb-2">
              <div class="col-md-6 d-flex align-items-center">
                <%= sif.object.stock_location.name %>
              </div>
              <div class="col-md-2">
                <%= sif.number_field :count_on_hand, class: 'form-control' %>
              </div>
              <div class="col-md-4">
                <div class="custom-control custom-checkbox d-flex align-items-center h-100">
                  <%= sif.check_box :backorderable, class: 'custom-control-input' %>
                  <%= sif.label :backorderable, Spree.t(:continue_selling_when_out_of_stock), class: 'custom-control-label' %>
                </div>
              </div>
            </div>
          <% end %>
        <% end %>
      </div>
    </div>
    <div class="row">
      <div class="col-md-6">
        <div class="form-group">
          <%= f.label :sku, Spree.t('admin.products.inventory.sku') %>
          <%= f.text_field :sku, class: 'form-control' %>
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          <%= f.label :barcode, Spree.t('admin.products.inventory.barcode') %>
          <%= f.text_field :barcode, class: 'form-control' %>
        </div>
      </div>
    </div>
  </div>
</div>
